package week10;

import java.util.Scanner;

public class Main3 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		ArrayUtils arr = new ArrayUtils();
		int n = in.nextInt();
		double[] a = new double[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = in.nextInt();
		}
		while(true)
		{
			try{
				int begin = in.nextInt();
				int end = in.nextInt();
				try{
					System.out.println(arr.findMax(a, begin, end));
				}
				catch(IllegalArgumentException e){
					System.out.println(e);
				}
			}
			catch(Exception e){
				try {
				     System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
				} catch (Exception e1) {
				}
				System.exit(0);
			}
		}
	}
}

class ArrayUtils
{
	public static double findMax(double[] arr,int begin, int end) throws IllegalArgumentException
	{
		if(begin>=end)
			throw new IllegalArgumentException("begin:"+begin+" >= end:"+end);
		if(begin<0)
			throw new IllegalArgumentException("begin:"+begin+" < 0");
		if(end>arr.length)
			throw new IllegalArgumentException("end:"+end+" > arr.length");
		double max=0;
		for (int i = begin; i < end; i++)  
	    {  
			if(arr[i]>max)
			max = arr[i];
	    }  
		return max;
	}
}